package cube.utils;

import cube.utils.exec.CmdExecutor;

/**
 * 系统命令执行工具
 * 
 * @author abiao
 */
public class CmdUtil {

	/**
	 * 执行命令并获取结果
	 */
	public static String exec(String cmd) {
		return exec(cmd, 0);
	}

	/**
	 * 执行命令并获取结果
	 */
	public static String exec(String cmd, int timeout) {
		final StringBuffer result = new StringBuffer();
		new CmdExecutor() {
			public void output(String s) {
				if (result.length() != 0) {
					result.append("\n");
				}
				result.append(s);
			}
		}.blockExecute(cmd, timeout);
		return result.toString();
	}

	/**
	 * 后台执行命令
	 */
	public static void dexec(String cmd) {
		new CmdExecutor().execute(cmd);
	}
}
